<?php
namespace App\Logic\calculate;

use Illuminate\Support\Facades\DB;

class Calculate
{
    public static function index()
    {

        //计算每个人的业绩 算力
       $userlist = DB::table('user')->select('id','path','username')->get();
       foreach($userlist as $v) {

           $downlist = DB::table('user')
               ->where('path','like',$v->path.$v->id.',%')
               ->select('username')
               ->get()->toArray();
           $username_arr = array_column($downlist,'username');
           $username_arr[] = $v->username;

           $cny = DB::table('order')
               ->whereIn('user_name',$username_arr)
               ->where('status',1)
               ->sum('all_cny');
           $update_arr['performance'] = $cny;

           $capacity = Db::table('miner_host as mh')
               ->join('miner_info as mi', 'mh.mid', '=', 'mi.mid')
               ->join('miner_user as mu', 'mu.mid', '=', 'mh.mid')
               ->whereIn('mu.user_name',$username_arr)
               ->sum('mh.hspace');
           $update_arr['capacity'] = $capacity;

           DB::table('user')->where('id',$v->id)->update($update_arr);


       }


    }


}





